<?php

class WorkAmountController extends Controller
{
    /*
    * 获取提现列表
    *
    */
    public function actionGetList()
    {
        try {
            //参数验证

            //检测
            $user_id = SessionService::getUserIDBySessionid();


            //获取列表
            $searchsql = Util::initSearchSql();

            $searchsql = Util::getSerarchStr($searchsql, "mobile", "mobile"); //手机号
            $searchsql = Util::getSerarchStr($searchsql, "status", "status"); //状态

            //排序
            $searchsql = $searchsql . " order by create_time  desc";
            //获取list
            $list = WorkerWithdrawRequest::model()->findAll($searchsql);


	            //返回数据
	            Util::responseList(count($list), $list);


	        } catch (Exception $e) {
            Util::responseErrorMsg($e->getMessage());

        }
    }

    /*
    * 获取请求对应的日志列表
    *
    */
    public function actionGetLogList()
    {
        try {
            //参数验证

            //检测
            $user_id = SessionService::getUserIDBySessionid();


            //获取列表
            $searchsql = Util::initSearchSql();

            $searchsql = Util::getSerarchStr($searchsql, "request_id", "request_id"); //请求id

            //排序
            $searchsql = $searchsql . " order by create_time  asc";
            //获取list
            $list = WorkerWithdrawRequestLog::model()->findAll($searchsql);


                //返回数据
                Util::responseList(count($list), $list);


            } catch (Exception $e) {
            Util::responseErrorMsg($e->getMessage());

        }
    }

    /*
    * 拒绝提现
    *
    */
    public function actionDenyRequest()
    {

        try {
            //检测
            $user_id = SessionService::getUserIDBySessionid();

            //参数验证
            $obj_id = Util::getParamNotEmpty("obj_id");
            $reason = Util::getParamNotEmpty("reason");


            //验证存在


            $obj = WorkerWithdrawRequest::model()->findByPK($obj_id);
            Util::checkExistAndNotDelete($obj);

            $worker = Worker::model()->findByPK($obj->worker_id);
            Util::checkExistAndNotDelete($worker);

            //验证状态
            if($obj->status != MsgConst::WITHDRAW_TYPE_SUBMITING)
                throw new Exception("该请求已处理");

            //

            //修改信息

            WorkerAccountService::denyWithdrawRequest($worker,$obj,$reason);

            //保存
            Util::saveObjData($obj);


            //返回数据
            Util::responseMsg(MsgConst::RETURN_SUCCESS);


        } catch (Exception $e) {
            Util::responseErrorMsg($e->getMessage());

        }
    }


    /*
    * 同意提现
    *
    */
    public function actionAcceptRequest()
    {

        try {
            //检测
            $user_id = SessionService::getUserIDBySessionid();

            //参数验证
            $obj_id = Util::getParamNotEmpty("obj_id");
            $reason = Util::getParam("reason","通过");


            //验证存在


            $obj = WorkerWithdrawRequest::model()->findByPK($obj_id);
            Util::checkExistAndNotDelete($obj);

            $worker = Worker::model()->findByPK($obj->worker_id);
            Util::checkExistAndNotDelete($worker);

            //验证状态
            if($obj->status != MsgConst::WITHDRAW_TYPE_SUBMITING)
                throw new Exception("该请求已处理");

            //

            //修改信息

            WorkerAccountService::acceptWithdrawRequest($worker,$obj,$reason);

            //保存
            Util::saveObjData($obj);


            //返回数据
            Util::responseMsg(MsgConst::RETURN_SUCCESS);


        } catch (Exception $e) {
            Util::responseErrorMsg($e->getMessage());

        }
    }

    /*
    * 获取银行流水列表
    *
    */

    public function actionGetBankCashList()
    {

        try {
            //参数验证

            //检测
            $user_id = SessionService::getUserIDBySessionid();


            //参数验证
            $worker_id = Util::getParamNotEmpty("worker_id");

            $searchsql = Util::initSearchSql();

            $searchsql = $searchsql." and worker_id = '".$worker_id."'";


            //获取count
            $totalcount = WorkerBankcash::model()->count($searchsql);

                //排序
                $searchsql = $searchsql . " order by create_time desc";

                //加上分页控制
                $searchsql = Util::addLimitSql($searchsql);

                //获取list
                $list =WorkerBankcash ::model()->findAll($searchsql);


                Util::responseList($totalcount, $list);

            } catch (Exception $e) {
            Util::responseErrorMsg($e->getMessage());

        }


    }




}